/*
 * Public libusb header file
 * Copyright (c) 2010 Chen Wang  <cnnbboy@163.com>
 *
 * This software is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include "QDnwSerialConfiguration.h"
#include "ui_QDnwSerialConfiguration.h"

QDnwSerialConfiguration::QDnwSerialConfiguration(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::QDnwSerialConfiguration)
{
    ui->setupUi(this);

    this->baudRate = "115200";
    this->comPort = "ttyS0";
}

QDnwSerialConfiguration::~QDnwSerialConfiguration()
{
    delete ui;
}

unsigned int QDnwSerialConfiguration::getDownAddr()
{
    this->downAddr = ui->DownLoadLineEdit->text().toInt();
    return this->downAddr;
}

QString QDnwSerialConfiguration::getBaudRate()
{
    if ( ui->radioButton115200->isChecked() ) {
        this->baudRate = ui->radioButton115200->text();
    }
    else if ( ui->radioButton57600->isChecked() ) {
        this->baudRate = ui->radioButton57600->text();
    }
    else if ( ui->radioButton38400->isChecked() ) {
        this->baudRate = ui->radioButton38400->text();
    }
    else if ( ui->radioButton19200->isChecked() ) {
        this->baudRate = ui->radioButton19200->text();
    }
    else if ( ui->radioButton14400->isChecked() ) {
        this->baudRate = ui->radioButton14400->text();
    }
    else if ( ui->radioButton9600->isChecked() ) {
        this->baudRate = ui->radioButton9600->text();
    }

    return this->baudRate;
}

QString QDnwSerialConfiguration::getComPort()
{
    if ( ui->ttyS0RdioButton->isChecked() ) {
        this->comPort = ui->ttyS0RdioButton->text();
    }
    else if ( ui->ttyS1RadioButton->isChecked() ) {
        this->comPort = ui->ttyS1RadioButton->text();
    }
    else if ( ui->ttyS2RadioButton->isChecked() ) {
        this->comPort = ui->ttyS2RadioButton->text();
    }
    else if ( ui->ttyUSB0RadioButton->isChecked() ) {
        this->comPort = ui->ttyUSB0RadioButton->text();
    }
    else if ( ui->ttyUSB1RadioButton->isChecked() ) {
        this->comPort = ui->ttyUSB1RadioButton->text();
    }

    return this->comPort;
}
